<template>
	<view class="box">
		<view class="flex" @click="endTime(1)" style="border-radius: 6px;border: #fa1e8a dashed 1px;line-height: 42px;box-sizing: border-box;padding: 0 10px;">
			开始时间：
			<view style="margin-left: auto;">{{ item.start_time }}</view>
		</view>
		<view class="flex" @click="endTime(2)" style="border-radius: 6px;border: #fa1e8a dashed 1px;line-height: 42px;box-sizing: border-box;padding: 0 10px;margin-top: 10px;">
			结束时间：
			<view style="margin-left: auto;">{{ item.end_time }}</view>
		</view>
		<!-- <u-cell-group><u-cell-item v-for="item in 5"  title="历史周期"></u-cell-item></u-cell-group> -->
		<view><view @click="baocun" class="button button1">保存</view></view>
		<view @click="shanchu"><view class="button2">删除</view></view>
		<u-picker @confirm="confirm" mode="time" v-model="show"></u-picker>
	</view>
</template>

<script>
export default {
	data() {
		return {
			item: {},
			show: false,
			index:0,
			type:0,
		};
	},
	methods: {
		async confirm(e) {
			const { year, month, day } = e;
			if(this.index==1){   
				console.log(e,'wwww')
				this.item.start_time= year + '-' + month + '-' + day
			}else{
				console.log(e,'ggggggggggg')
				this.item.end_time= year + '-' + month + '-' + day
			}
			// const { year, month, day } = e;

			// const time = year + '-' + month + '-' + day;
			
		},
		async shanchu(){
			let data={
				aunt_id:this.item.id
			}
			let res = await this.$u.api.auntdel(data)
			setTimeout(()=>{
				uni.navigateBack()
			},300)
		},
		async setavg(){
			let data={
				start_time:this.item.start_time,
				end_time:this.item.end_time
			}
			let res = await this.$u.api.aunthistory(data)
			uni.showToast({
				title:'添加成功',
				icon:'none'
			})
			setTimeout(()=>{
				uni.navigateBack()
			},300)
			// this.navBack();
		},
		async aunt_save(){
			let data={
				time:this.item.end_time
			}
			let res = await this.$u.api.aunt_save(data);
			uni.showToast({
				title:'编辑成功',
				icon:'none'
			})
			setTimeout(()=>{
				uni.navigateBack()
			},300)
			// this.navBack();
		},
		baocun(){
			if(this.type==1){
				this.setavg()
			}else{
				this.aunt_save()
			}
		},
		endTime(e) {
			this.index=e
			if (e==1&this.type!=1) return;
			this.show = true;
		}
	},
	onLoad({ item }) {
		this.type=item
		if (item!=1) {
			this.item = JSON.parse(decodeURIComponent(item));
		}else{
			uni.setNavigationBarTitle({
				title:"设置记录"
			})
		}

		uni.setNavigationBarColor({
			frontColor: '#000000',
			backgroundColor: '#ffffff'
		});
	}
};
</script>

<style>
page {
	background: #fff;
}
.button1 {
	width: 300px;
	line-height: 40px;
	text-align: center;
	margin: 10px auto 0px;
}
.button2 {
	width: 300px;
	line-height: 40px;
	text-align: center;
	margin: 10px auto 0px;
	border: #fa1e8a solid 1px;
	box-sizing: border-box;
	color: #fa1e8a;
	border-radius: 30px;
	height: 40px;
}
</style>
